package com.lcf.system.controller;

import com.lcf.framework.annotation.PermissionCheck;
import com.lcf.system.dto.userRole.SysUserRoleDTO;
import com.lcf.system.service.SysUserRoleService;
import com.lcf.system.vo.userRole.SysUserRoleVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.lcf.framework.enums.PermissionEnum.SYS_USER_ROLE_GET;
import static com.lcf.framework.enums.PermissionEnum.SYS_USER_ROLE_SET;

/**
 * 用户与角色(SysUserRole)表控制层
 *
 * @author lcf
 * @since 2025-02-28 15:11:09
 */
@Tag(name = "用户与角色")
@RestController
@RequestMapping("sysUserRole")
public class SysUserRoleController {
    @Resource
    private SysUserRoleService sysUserRoleService;

    /**
     * 设置用户角色
     */
    @Operation(summary = "设置用户角色")
    @PermissionCheck(SYS_USER_ROLE_SET)
    @PostMapping("{userId}")
    public void setUserRole(@PathVariable @Schema(description = "用户id") long userId,
                            @RequestBody @Validated SysUserRoleDTO sysUserRole) {
        sysUserRoleService.setUserRole(userId, sysUserRole);
    }

    /**
     * 获取用户角色
     */
    @Operation(summary = "获取用户角色")
    @PermissionCheck(SYS_USER_ROLE_GET)
    @GetMapping("{userId}")
    public List<SysUserRoleVO> getUserRole(@PathVariable @Schema(description = "用户id") long userId) {
        return sysUserRoleService.getUserRole(userId);
    }
}

